<template>
	<view class="add-staff">
		<view class="add-staff-cell-group">
			<view class="add-staff-cell">
				<text>员工ID</text>
				<input type="number" placeholder="请输入员工ID" v-model="user_id" />
			</view>
			<view class="add-staff-cell">
				<text>提成(%)</text>
				<input type="number" placeholder="建议提成1-10%" maxlength="3" v-model="royalty" />
			</view>
		</view>
		<view class="add-staff-btn" @click="add">添加</view>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				royalty: '',
				user_id: ''
			};
		},
		methods: {
			add() {
				let user_id = this.user_id
				let royalty = this.royalty
				let store_id = JSON.parse(uni.getStorageSync('userInfo')).store_id;
				if (user_id == '') {
					uni.showToast({
						title: 'ID不能为空',
						icon: 'none',
						duration: 2000
					})
					return
				}
				if (royalty < 0) {
					uni.showToast({
						title: '提成不能小于0',
						icon: 'none',
						duration: 2000
					})
					return
				} else if (royalty > 100) {
					uni.showToast({
						title: '提成不能大于100',
						icon: 'none',
						duration: 2000
					})
					return
				}
				let data = {
					type: 5,
					role_type: 1,
					royalty: royalty,
					user_id: user_id,
					store_id: store_id
				}

				this.$u.apiWei.StaffAdd(data).then(res => {
					uni.showToast({
						title: res.datas,
						icon: 'success',
						duration: 2000,
						success: () => {
							uni.redirectTo({
								url: '/my/staff/staff'
							})
						},
					})
				})
			},
		}
	}
</script>

<style lang="scss">
	.add-staff {

		.add-staff-cell {
			display: flex;
			background-color: #FFF;
			padding: 30rpx 20rpx;
		}

		text {
			width: 160rpx;
			line-height: 78rpx;
		}

		input {
			flex: 1;
			text-align: right;
			height: 78rpx;
			line-height: 78rpx;
			background-color: #F3F3F3;
			padding: 0 20rpx;
		}

		.add-staff-btn {
			margin: 0 auto;
			margin-top: 82rpx;
			width: 600rpx;
			height: 100rpx;
			line-height: 100rpx;
			text-align: center;
			font-size: 36rpx;
			color: #fff;
			background: #FE9B26;
			border-radius: 50rpx;
		}

	}
</style>
